﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using SMSGateway.Threading;

namespace ProcessesSMS
{
	/// <summary>
	/// Summary description for MOWorkItem.
	/// </summary>

	public class MOWorkItem:WorkItem
	{
		#region Properties
		private SMS_MO MO;
		#endregion
		
		
		public MOWorkItem(int MO_ID,string UserID,string ServiceID,string CommandCode,string MessageInfo,int RequestID,DateTime RequestTime)
		{
			//
			// TODO: Add constructor logic here
			//
			MO = new SMS_MO(MO_ID,UserID,ServiceID,CommandCode.ToUpper(),MessageInfo,RequestID,RequestTime);			
		}

		public MOWorkItem(int MO_ID,string UserID,string ServiceID,string CommandCode,string MessageInfo,int RequestID,DateTime RequestTime,int count)
		{
			//
			// TODO: Add constructor logic here
			//
			MO = new SMS_MO(MO_ID,UserID,ServiceID,CommandCode.ToUpper(),MessageInfo,RequestID,RequestTime,count);			
		}

		public override void Perform()
		{						
			#region VIT
			//Kiem tra gioi han 
			SMS_Limit CheckLimit = new SMS_Limit();
			string Limit = CheckLimit.OverLimit(MO.UserID, MO.CommandCode, MO.ServiceID);
			if (Limit != "")
			{
				SMS_MT _MT;
				_MT = new SMS_MT(MO);
				SMS_STR TMSTR = new SMS_STR();
				_MT.AddMessage(MO.UserID, Limit,SMS_ContentType.SMS_TEXT);				
				_MT.MsgType = SMS_MsgType.SMS_TINHTIEN;
				_MT.Insert();
				return;
			}			
			#region CHUNG KHOAN
			if (MO.CommandCode.ToUpper() == "CKVN")
			{
				CKVN CKVN = new CKVN(MO);
				CKVN.run();
			}	
				#endregion					
			#region SMS XO SO
			else if((MO.CommandCode.ToUpper() == "XSTD") || (MO.CommandCode.ToUpper() == "XSMB") || (MO.CommandCode.ToUpper() == "SXTD") || (MO.CommandCode.ToUpper() == "SXMB"))//1.ket qua xs TD moi nhat, 2. ket qua xs TD theo ngay, 3.tuong thuat truc tiep ket qua
			{
				XOSO XOSO = new XOSO(MO);
				XOSO.run();
			}
			else if(MO.CommandCode.ToUpper() == "XS")//xo so cac tinh mien Trung va mien Nam, cho nhan ket qua cac tinh
			{
				XOSO_MT XOSO_MT = new XOSO_MT(MO);
				XOSO_MT.run();
			}
			else if(MO.CommandCode.ToUpper() == "XSMT")//xem toan bo ket qua xo so mien Trung ngay moi nhat
			{
				XSMT XSMT = new XSMT(MO);
				XSMT.run();
			}
			else if(MO.CommandCode.ToUpper() == "XSMN")//xem toan bo ket qua xo so mien Nam ngay moi nhat
			{			
				XSMN XSMN = new XSMN(MO);
				XSMN.run();
			}
			else if(MO.CommandCode.ToUpper() == "DS")//thong ke
			{
				DS DS = new DS(MO);
				DS.run();
			}
			else if (MO.CommandCode.ToUpper() == "DD") // DU DOAN SO PHAT TAI
			{
				XOSO_DD XOSO_DD = new XOSO_DD(MO);
				XOSO_DD.run();
			}
			else if (MO.CommandCode.ToUpper() == "CAU") // CAU LO TUNG BUNG
			{
				XOSO_CAU XOSO_CAU = new XOSO_CAU(MO);
				XOSO_CAU.run();
			}
			else if (MO.CommandCode.ToUpper() == "SOI") // SOI SO DAI LOC
			{
				XOSO_SOI XOSO_SOI = new XOSO_SOI(MO);
				XOSO_SOI.run();
			}
//			else if (((MO.CommandCode.ToUpper()=="TD") ||(MO.CommandCode.ToUpper()=="MB") || (MO.CommandCode.ToUpper()=="HN") || 	(MO.CommandCode.ToUpper()=="QN") || (MO.CommandCode.ToUpper()=="BN") || (MO.CommandCode.ToUpper()=="HP") || (MO.CommandCode.ToUpper()=="ND") || (MO.CommandCode.ToUpper()=="TB")) && ((MO.UserID=="84984696925") || (MO.UserID=="84988901114")))//Nhap du lieu xo so qua dien thoai
//			{			
//				NHAPXS NHAPXS = new NHAPXS(MO);
//				NHAPXS.InsertResultDBTT(MO.Message);
//			}
				#endregion					
			#region Cu phap nap tien cua VietWeb
			else if((MO.CommandCode.ToUpper()=="TV") || (MO.CommandCode.ToUpper()=="TC") || (MO.CommandCode.ToUpper()=="TLH"))
			{
				VIETWEB VIETWEB = new VIETWEB(MO);
				VIETWEB.run();
			}
				#endregion
			#region Cu phap nap tien NAP
			else if (MO.CommandCode.ToUpper()=="NAP")
			{
				CAUVANG CAUVANG = new CAUVANG(MO);
				CAUVANG.run();
			}
				#endregion
			#region Cu phap THOI TIET
			else if (MO.CommandCode.ToUpper()=="TT")
			{
				THOITIET THOITIET = new THOITIET(MO);
				THOITIET.run();
			}
				#endregion
			#region Cu phap DAU GIA
			else if(MO.CommandCode.ToUpper()=="DG" || MO.CommandCode.ToUpper()=="KQ")
			{
				DAUGIA DAUGIA = new DAUGIA(MO);
				DAUGIA.run();
			}
				#endregion
			#region Cu phap SOIKEO
			else if ((MO.CommandCode.ToUpper()=="TIP") || (MO.CommandCode.ToUpper()=="TIP2") || (MO.CommandCode.ToUpper()=="TIP3") || (MO.CommandCode.ToUpper()=="SS")|| (MO.CommandCode.ToUpper()=="AM")|| (MO.CommandCode.ToUpper()=="AT"))
			{
				SOIKEO SOIKEO = new SOIKEO(MO);
				SOIKEO.run();
			}
				#endregion
			#region Cu phap MuaVN: MS,MV,MD,MR,MA,MP,KT,XSTP,VIP,SMS,TIB
			else if ((MO.CommandCode.ToUpper()=="MS") || (MO.CommandCode.ToUpper()=="MV") || (MO.CommandCode.ToUpper()=="MD") || (MO.CommandCode.ToUpper()=="MR") || (MO.CommandCode.ToUpper()=="MA") ||(MO.CommandCode.ToUpper()=="MP") ||(MO.CommandCode.ToUpper()=="KT"))
			{
				MUAVN MUAVN = new MUAVN(MO);
				MUAVN.run();
			}
				#endregion
			#region Con thoi thi truong
			else if ((MO.CommandCode.ToUpper()=="CT")|| (MO.CommandCode.ToUpper()=="TL") || (MO.CommandCode.ToUpper()=="ND"))
			{
				CONTHOITHITRUONG CONTHOITHITRUONG = new CONTHOITHITRUONG(MO);
				CONTHOITHITRUONG.run();
			}
			#endregion
			#region Xong dat xong nha
			else if (MO.CommandCode.ToUpper()=="XD")
			{
				XONGDATXONGNHA XONGDATXONGNHA = new XONGDATXONGNHA(MO);
				XONGDATXONGNHA.run();
			}
			#endregion

			else
			{
				SMS_MT _MT;
				_MT = new SMS_MT(MO);
				SMS_STR TMSTR = new SMS_STR();
				_MT.AddMessage(MO.UserID,ConfigSettings.ReadSetting("SMS_HELP"),SMS_ContentType.SMS_TEXT);				
				_MT.MsgType = SMS_MsgType.SMS_TINHTIEN;
				_MT.Insert();
				return;
			}
			#endregion
		}
	}
}
